﻿namespace SKNotes.Utilities
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Data;


    [ValueConversion(typeof(InvokeOC<NoteTag>), typeof(string))]
    class TagCollectionToStringConverter : IValueConverter
    {
        public int Value { get; set; }

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            lock (this)
            {
                InvokeOC<NoteTag> collection = (InvokeOC<NoteTag>)value;
                if (collection != null)
                {
                    StringBuilder builder = new StringBuilder();
                    foreach (NoteTag t in collection)
                    {
                        if (builder.Length != 0)
                        {
                            builder.Append(", ");
                        }
                        builder.Append(t.TagName);
                    }
                    return builder.ToString();
                }
                return string.Empty;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
